package com.example.manager.ui;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.os.Bundle;
import android.view.MenuItem;

import com.example.manager.FrameLayout.detailsFragment;
import com.example.manager.FrameLayout.discoverFragment;
import com.example.manager.FrameLayout.musicFragment;
import com.example.manager.FrameLayout.my_listFragment;
import com.example.manager.FrameLayout.settingsFragment;
import com.example.manager.R;
import com.google.android.material.navigation.NavigationView;

import org.jetbrains.annotations.NotNull;

public class musicActivity extends AppCompatActivity {
    private NavigationView navigationView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_music);

        // 获取导航视图
        navigationView = findViewById(R.id.navigationView);

        // 设置导航视图菜单项的点击事件监听器
        navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull @NotNull MenuItem item) {
                // 处理导航菜单项的点击事件
                switch (item.getItemId()) {
                    case R.id.nav_music:
                        replaceFragment(new musicFragment());
                        break;
                    case R.id.nav_discover:
                        replaceFragment(new discoverFragment());
                        break;
                    case R.id.nav_my_list:
                        replaceFragment(new my_listFragment());
                        break;
                    case R.id.nav_details:
                        replaceFragment(new detailsFragment());
                        break;
                    case R.id.nav_settings:
                        replaceFragment(new settingsFragment());
                        break;
                }

                return true; // 返回 true 表示已处理点击事件
            }
        });

        // 默认显示音乐碎片
        replaceFragment(new musicFragment());
    }

    // 用于替换碎片的方法
    private void replaceFragment(Fragment fragment) {
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.contentFrameLayout, fragment)
                .commit();
    }
}
